<template>
	<view>
		<view class="flex" style="padding: 12px 15px; background-color: #fff">
			<view style="font-size: 14px; color: #1d1f20; font-weight: 400">当前统计的到账日期：</view>
			<view style="font-size: 14px; color: #ff3331; font-weight: 400">{{ dzrq }}</view>
		</view>
		<view style="padding: 15px">
			<view class="flex" style="padding: 15px; justify-content: space-between; background: #fff; border-radius: 10px">
				<view>
					<view style="font-size: 16px; font-weight: bold; color: #1d1f20">累计佣金(筛选汇总)</view>
					<view style="font-size: 14px; font-weight: 400; color: #1d1f20; margin-top: 10px">
						结算订单数：{{ project.num == null ? 0 : project.num }}单
					</view>
				</view>
				<view style="font-size: 14px; font-weight: bold; color: #ff3331">
					{{ project.sum == null ? 0 : project.sum }}元
				</view>
			</view>
			<view style="margin-top: 15px; border-radius: 10px; background-color: #fff">
				<view class="flex" style="border-radius: 10px 10px 0 0; background-color: #ff3331">
					<view class="req">结算标准</view>
					<view class="req">结算订单数</view>

					<view class="req">佣金补贴</view>
				</view>
				<view v-for="(it, i) in rep_info.settList" class="flex iy" style="border-radius: 0 0 10px 10px">
					<view class="reqs">{{ it.projectlist.name }}</view>
					<view class="reqs">{{ it.num }}单</view>
					<view style="color: #ff3331 !important" class="reqs">{{ it.sum }}元</view>
				</view>
			</view>
			<view style="margin: 30px 0px 15px">
				<view style="font-size: 16px; font-weight: bold; color: #1d1f20">业务员推广码数据：</view>
				<view
					v-for="(it, i) in rep_info.applyList"
					style="padding: 0px 15px; background-color: #ffffff; margin-top: 15px; border-radius: 5px"
				>
					<view class="flex" style="justify-content: space-between; padding: 15px 0; border-bottom: 1px solid #f3f3f3">
						<view style="color: #1d1f20; font-weight: bold; color: #1d1f20">业务员：{{ it.applyname }}</view>
						<view @click="guanf(it)" class="flex" style="justify-content: space-between">
							<view style="font-size: 14px; font-weight: 400; color: #777979; margin-right: 8px">官方明细</view>
							<u-icon name="arrow-right" size="18"></u-icon>
						</view>
					</view>
					<view style="padding: 15px 0; margin-bottom: 10px">
						<view class="flex" style="">
							<view class="standard">结算标准</view>
							<view class="standard">结算订单数</view>
							<view class="standard">佣金补贴</view>
						</view>
						<view class="flex kou" style="justify-content: space-between" v-for="(item, index) in it.list">
							<view class="stans">{{ item.projectlist.name }}</view>
							<view class="stans">{{ item.num }}</view>
							<view style="color: #ff3331 !important" class="stans">{{ item.sum }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				project_id: '',
				rep_info: '',
				project: '',
				time: '',
				stime: '',
				etime: '',
				dzrq: '',
			};
		},
		onLoad(e) {
			this.time = e.time;
			this.stime = e.stime;
			this.etime = e.etime;
			if (this.time == '') {
				if (this.stime == '') {
					this.dzrq = uni.$u.timeFormat('', 'yyyy-mm-dd');
				} else {
					this.dzrq =
						uni.$u.timeFormat(this.stime, 'yyyy-mm-dd') +
						'至' +
						uni.$u.timeFormat(this.etime, 'yyyy-mm-dd').substr(5, 6);
				}
			} else {
				let date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				date.setMonth(month);
				date.setDate('1');
				// 获取本月最后一天
				let dd = date.setDate(date.getDate() - 1);
				let els = uni.$u.timeFormat(dd, 'yyyy-mm-dd');
				if (this.time == 'month') {
					this.dzrq = year + '-' + month + '-' + '01' + '至' + els;
				} else if (this.time == 'yesterday') {
					this.dzrq = year + '-' + month + '-' + day + '至' + year + '-' + month + '-' + (day - 1);
				} else {
					this.dzrq = uni.$u.timeFormat('', 'yyyy-mm-dd');
				}
			}

			this.project_id = e.project_id;
			this.info();
		},
		methods: {
			guanf(it) {
				// /pages/project/official?project_id=33&name=孙涵&applyphone=18256930799
				uni.navigateTo({
					url:
						'/pages/project/official?project_id=' +
						this.project_id +
						'&name=' +
						it.applyname +
						'&applyphone=' +
						it.applyphone,
				});
			},
			async info() {
				let res = await this.$http.index.projectReport({
					project_id: this.project_id,
					stime: this.stime,
					etime: this.etime,
					time: this.time,
				});
				console.log(res);
				if (res.code == 1) {
					this.rep_info = res.data;
					this.project = res.data.project[0];
				}
			},
			official() {
				uni.navigateTo({
					url: '/pages/project/official',
				});
			},
		},
	};
</script>
<style scoped lang="scss">
	.standard {
		font-size: 14px;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #797b7b;
		width: 33.33%;
		text-align: center;
	}

	.stans {
		font-size: 14px;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #1d1f20;
		width: 33.33%;
		text-align: center;
	}

	.kou {
		margin-top: 10px;
	}

	.req {
		width: 33.33%;
		text-align: center;
		padding: 15px 0;
		font-size: 14px;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #ffffff;
	}

	.iy {
		border-bottom: 1px solid #f3f3f3;

		&:last-child {
			border-bottom: none;
		}
	}

	.reqs {
		width: 33.33%;
		text-align: center;
		padding: 15px 0;
		font-size: 14px;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #1d1f20;
	}
</style>

<style>
	page {
		background-color: #f7f9fa;
	}
</style>
